package testcase;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * @author: zhang.rongqing
 * @since: 2019/10/29
 */
public class DateUtil {
    public static Date formatCreateTime(Date createTime) {
        try {
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if (createTime == null) {
                return new Date();
            }
            Calendar ca = Calendar.getInstance();
            ca.setTime(createTime);
            ca.add(Calendar.HOUR, -8);
            String newValue = f.format(ca.getTime());
            return f.parse(newValue);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Date();
    }

    public static Date formatCreateTime2(Date createTime) {
        Instant instant = Instant.ofEpochSecond(createTime.getTime());
//        LocalDate localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate();
        LocalDateTime localDateTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
        localDateTime.minusHours(8);
        return null;
    }

    public static void main(String[] args) {
        Date resultDate = DateUtil.formatCreateTime(new Date("2019/09/02 07:00:00"));
        System.out.println(resultDate);
        System.out.println(resultDate.getTime());
    }
}
